package com.example.mobile2021606158zl0413;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private Button btnMainSupplier;
    private Button btnMainBuy;
    private TextView tvMainEsult;
    private Button btnMainClose;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnMainClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog dialog;
                AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("普通对话框");
                builder.setMessage("是否确定退出应用？");
                builder.setPositiveButton("确定",new DialogInterface.OnClickListener(){

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                  dialog.dismiss();
                                  MainActivity.this.finish();
                            }
                        });
                builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                dialog=builder.create();
                dialog.show();
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        btnMainSupplier = (Button) findViewById(R.id.btn_main_supplier);
        btnMainBuy = (Button) findViewById(R.id.btn_main_buy);
        tvMainEsult = (TextView) findViewById(R.id.tv_main_esult);
        btnMainClose = (Button) findViewById(R.id.btn_main_close);
    }
}